package com.ssextjs.component.grid;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import com.ssextjs.component.Component;
import com.ssextjs.component.Panel;
import com.ssextjs.component.Toolbar;
import com.ssextjs.data.Store;
import com.ssextjs.engine.ConfiguraionImpl;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class GridPanel extends Panel{
	public boolean forceFit = true;
	public boolean stripeRows = true;
	public ColumnModel cm = null;
	public Store store = null;
	
	public GridPanel(Map opt) {
		super();
		setMapOpt(opt);
	}
	
	public GridPanel(Store st,ColumnModel cm,String title) {
		this.store=st;
		this.cm=cm;
		this.title=title;
	}
	
	public String toString() {
		createConfig();
		tplInit();
		String html="";
		try {
			html = ProcessTemplate(ConfiguraionImpl.getCfg().getTemplate("GridPanel.tpl"),mainopt);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.html = html;
		mainopt.put("html", html);
		String res=ProcessTemplate(tpl,mainopt);
		return res;
	}
	
	public GridPanel setTbar(Toolbar tbar) {
		if (this.title==null || this.title.isEmpty()) {
			tbar.noHeader(true);
		}else{
			tbar.noHeader(false);
		}
		this.tbar=tbar;
		return this;
	}
	 
	public Component getTbar() {
		return this.tbar;
	}
	
	public GridPanel setBbar(Component bbar) {
		this.bbar=bbar;
		return this;
	}
	
	public Component getBbar() {
		return this.bbar;
	}
	
	public GridPanel setForceFit(boolean fl) {
		this.forceFit=fl;
		return this;
	}
	
	public boolean getForceFit() {
		return this.forceFit;
	}
	
	public GridPanel setStripeRows(boolean fl) {
		this.stripeRows=fl;
		return this;
	}
	
	public boolean getStripeRows() {
		return this.stripeRows;
	}
	
	public GridPanel setColumnModel(ColumnModel cm) {
		this.cm=cm;
		return this;
	}
	public ColumnModel getColumnModel() {
		return this.cm;
	}
	
	
}
